package com.spring.controller;

import com.spring.dao.ProductBeanMapper;
import com.spring.domain.ProductBean;
import com.spring.domain.ResultBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@org.springframework.web.bind.annotation.RestController
@RequestMapping("/res")
public class RestController {
    @Autowired
    ProductBeanMapper productBeanMapper;

    @GetMapping("{id}")
    public ResultBean getProductInfo(@PathVariable("id")Integer id){
        System.out.println("proID:"+id);
        ProductBean productBean = productBeanMapper.selectByPrimaryKey(id);
        if (null == productBean){
            return ResultBean.ofFail(501,"未查到此商品");
        }
        ResultBean ret = ResultBean.ofSuccess(productBean,"查询成功");
        System.out.println(ret.getMsg());
        System.out.println(ret.getData().getProductName());
        return ret;

    }
//
//    @RequestMapping(value = "/product/{id}",method = RequestMethod.GET)
//    public ResultBean getProductInfo(@PathVariable("id")Integer id,HttpServletRequest request, HttpServletResponse response){
//        //@ResponseBody
//        System.out.println("proID:"+id);
//        ProductBean productBean = productBeanMapper.selectByPrimaryKey(id);
//        if (null == productBean){
//            return ResultBean.ofFail(501,"未查到此商品");
//        }
//        ResultBean ret = ResultBean.ofSuccess(productBean,"查询成功");
//        System.out.println(ret.getMsg());
//        System.out.println(ret.getData().getProductName());
//        return ret;
//    }


}
